<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<meta content="telephone=no" name="format-detection">
		<meta content="email=no" name="format-detection">
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<meta content="caibaojian" name="author" />
		<title>邀请注册</title>
		<link rel="stylesheet" href="css/share.css">
		<style type="text/css">
			body,
			html {
				background-color: #FFD042;
			}
			.content{
				position: relative;
				height: 667px;
				background: url(img/share_bcimg.png) no-repeat center;
				background-size: 100% 100%;
			}
			
			.bg {
				background-size: 100% 100%;
				color: #ffffff;
				text-align: center;
			}
			
			.bg h1 {
				font-size: 0.7rem;
				padding: 1.26rem 0 0.56rem 0;
			}
			
			.bg p {
			}
			
			.title_p {
				font-size: 0.32rem;
				color: #515151;
				text-align: center;
			}
			.new_img{
				padding-top: 3.8rem;
				display: block;
				margin: 0 auto;
				width: 80%;
			}
			input::-webkit-input-placeholder{
			        color: #ccc;
			}
			input::-moz-placeholder{ 
			        color: #ccc;        
			}
			input::-ms-input-placeholder{ 
			        color: #ccc;        
			}
			
			.rel_box{
				position: absolute;
				bottom: 40px;
				width: 100%;
			}
			
			button {
				display: block;
				width: 5.91rem;
				height: 0.9rem;
				margin: 0 auto;
				border-radius: 1.2rem;
				border: none;
				color: #9a742e;
				line-height: 0.9rem;
				text-align: center;
				background: transparent;
			}
			.title_p_big{
				font-size: 0.6rem;
				color: #333;
				font-weight: 600;
			}
			.title_p_line{
				width: 1rem;
				margin: 0.6rem auto;
			}
			.title_p_code{
				color: #FF7741;
				font-size: 0.52rem;
			}
			.input {
				display: block;
				width: 9.52rem;
				height: 1.6rem;
				border-radius: 0.8rem;
				text-indent: 0.3rem;
				margin: 0.5rem auto 0;	
				border: 1px solid transparent ;
				overflow: hidden;
				background: #FFF;
				display: flex;
				align-items: center;
			}
			.input input{
				padding-left: 0.4rem;
				width: 100%;
				height: 100%;
				border: none;
				background: transparent ;
				font-size: 0.56rem;
			}
			input:focus{   
				border:none;
			}
			.input .login_input2{
				width: 60%;
			}
			.getReg{
				height: 100%;
				width: 40%;
				color: #FF7D44;	
			}
			.registerbtn{
				width: 195px;
				height: 40px;
				color: transparent;
				margin-top: .8rem;
				background: url(img/164bnkn.png) no-repeat center;
				background-size: 100% 100%;
			}
			#notice1{
				display: none;
				color: #FF7D44;
			}
		</style>
		<script src="js/jquery.js"></script>
		<script type="text/javascript">
			function setfont() {
				var num = 1 / window.devicePixelRatio;
				var fontSize = document.documentElement.clientWidth / 15;
				document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px';
			}
			(function() {
				setfont()
			})()
			window.onresize = function() {
				setfont()
			}
		</script>
	</head>

	<body>
		<div class="content bg">
			<div class="rel_box">
				<div class="input">
					<input type="tel" name="mobile" class=" login_input f_15" autocomplete="off" placeholder="请输入您的手机号">
				</div>
				
				
				<div class="input form-group flex model_input">
					<label>完成验证：</label>
					<div id="captcha1">
						<p id="wait1" class="show"></p>
					</div>
				</div>
				<p id="notice1" class="hide">请先完成验证</p>
				
				<div class="input">
					<input type="text" name="smscode" autocomplete="off" class="login_input2 f_15" placeholder="输入验证码" v-model="accountPassword">
					<button href="javascript:;" class="login_a f_15 getReg" onclick="get_code(this)">获取验证码</button>
				</div>
				<div class="input">
					<input type="password" name="code" class=" login_input f_15" autocomplete="off" placeholder="请设置密码">
				</div>
				<button class="registerbtn" onclick="smsLogin()"></button>
			</div>
		</div>
	</body>
	
	<script src="./js/gt.js"></script>
	<script>
	
		var handler1 = function(captchaObj) {
			$("#get_code").click(function(e) {
				var result = captchaObj.getValidate();
				if (!result) {
					$("#notice1").show();
					setTimeout(function() {
						$("#notice1").hide();
					}, 2000);
					e.preventDefault();
				} else {
					get_code()
				}
			});
		
			// 将验证码加到id为captcha的元素里，同时会有三个input的值用于表单提交
			captchaObj.appendTo("#captcha1");
			captchaObj.onReady(function() {
				$("#wait1").hide();
			});
		};
		
		$.ajax({
			url: "https://api.aideapi.com/api/geetest.htm?t=" + (new Date()).getTime(), // 加随机数防止缓存
			type: "get",
			dataType: "json",
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				// 调用 initGeetest 初始化参数
				// 参数1：配置参数
				// 参数2：回调，回调的第一个参数验证码对象，之后可以使用它调用相应的接口
				initGeetest({
					gt: data.gt,
					challenge: data.challenge,
					new_captcha: data.new_captcha, // 用于宕机时表示是新验证码的宕机
					offline: !data.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
					product: "float", // 产品形式，包括：float，popup
					width: "100%"
				}, handler1);
			}
		});
		
		
		
		
		
		
	
		
		var recommendss = getParam("recommend")
		var recommend = recommendss.split('_')[0]
		var shopid = recommendss.split('_')[1]
		var telReg = /^1[0-9]{10}$/,
			toggle = true,
			i = 60,
			host = 'https://api.aideapi.com/api/router/',
			host_configure = '?app_id=SHOP_APP&secret_id=shopappWSPobnqU4iCzO4IPyRhBKOODjiHDcGT&secret_key=3f4511c9ff9c4c04b03781e3df19c82shopapp' + '&shopid=' + shopid,
			userreg = host + 'user.reg' + host_configure + '&client=1',
			getsmscode = host + 'system.smscode' + host_configure;
			// 获取邀请人信息
			query_recommend = 'https://api.aideapi.com/api/router/recommend.query?app_id=SHOP_APP&secret_id=shopappWSPobnqU4iCzO4IPyRhBKOODjiHDcGT&secret_key=3f4511c9ff9c4c04b03781e3df19c82shopapp' + '&shopid=' + shopid;
			
			
			
			
			
		function getParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if(r != null) return unescape(r[2]);
			return null; //返回参数值
		}
		
		// initdata(recommend)
		
		$('#recommend').html(recommend)
		
		function initdata(recommend) {
			$.ajax({
				url: query_recommend,
				type: 'get',
				// contentType: "application/x-www-form-urlencoded",
				data: {
					recommend: recommend,
				},
				dataType: 'json',
				success: function(res) {
					if(res.code == 0) {
						if(res.member){
							if(res.member.data.name){
								$('#recommend-name').html(res.member.data.name)
							}
						}
						
						
					} else {
						// alert(result.msg);
						return;
					}
				},
				error: function(result) {
					alert("服务器繁忙，请重试！");
				}
			})
		}
		
		
		function get_code(self) {
			var geetest_challenge = $("input[name='geetest_challenge']").val()
			var geetest_validate = $("input[name='geetest_validate']").val()
			var geetest_seccode = $("input[name='geetest_seccode']").val()
			
			
			if($('input[name=mobile]').val().replace(/\s/g, '') == '' || !telReg.test($('input[name=mobile]').val().replace(/\s/g, ''))) {
				alert('请输入正确的手机号');
				return;
			} else {
				if(toggle) {
					$(self).attr('disabled', 'disabled');
					$.ajax({
						url: getsmscode,
						type: 'post',
						contentType: "application/x-www-form-urlencoded",
						data: {
							format:'json',
							mobile: $('input[name=mobile]').val(),
							geetest_challenge:geetest_challenge,
							geetest_validate: geetest_validate,
							geetest_seccode: geetest_seccode
						},
						dataType: 'json',
						crossDomain: true,
						xhrFields: {
							withCredentials: true
						},
						success: function(res) {
							if(res.code == 0) {
								toggle = false;
								$('.getReg').html('60s');
								timEnd = setInterval(function() {
									if(i > 1) {
										i--;
										$('.getReg').html(i + 's');
									} else {
										clearInterval(timEnd);
										$('.getReg').html('获取验证码');
										i = 60;
										toggle = true;
										$(self).removeAttr('disabled')
									}
								}, 1000);
							} else {
								alert(res.msg);
								$(self).removeAttr('disabled')
								return;
							}
						},
						error: function(result) {
							alert("服务器繁忙，请重试！");
							toggle = false;
							$('.getReg').html('60s');
							timEnd = setInterval(function() {
								if(i > 1) {
									i--;
									$('.getReg').html(i + 's');
								} else {
									clearInterval(timEnd);
									$('.getReg').html('获取验证码');
									i = 60;
									toggle = true;
									$(self).removeAttr('disabled')
								}
							}, 1000);
						}
					})
				} else {
					return;
				}
			}
		}

		function smsLogin() {
			var clientid = "";
			var loginInfo = {
				mobile: $('input[name=mobile]').val(),
				smscode: $('input[name=smscode]').val(),
				code: $('input[name=code]').val(),
				recommend: recommend
			};
			if(!telReg.test(loginInfo.mobile.replace(/\s/g, ''))) {
				alert('请输入正确的手机号码')
				return;
			} else if(!loginInfo.smscode) {
				alert('请输入验证码不能为空')
				return;
			} else if(!loginInfo.code) {
				alert('请输入密码')
				return;
			} else {
				$.ajax({
					url: userreg,
					type: 'post',
					data: loginInfo,
					dataType: 'json',
					success: function(res) {
						if(res.code == 0) {
							alert('注册成功');
							location.href = "down.html?shopid=" + shopid;
						} else {
							alert(res.msg);
						}
					},
					error: function(result) {
						alert("服务器繁忙，请重试！");
					}
				})
			}
		}
	</script>
</html>